package com.dq.domain.base;

import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

/**
 * 实体父类监听器
 * @author ----
 */
public class BaseEntityListener {

    @PreUpdate
    public void preUpdate(BaseEntity entity) {
        entity.setLastModifyTime(System.currentTimeMillis());
    }

    @PrePersist
    public void prePersist(BaseEntity entity) {
        if(entity.getCreateTime() == null) {
            entity.setCreateTime(System.currentTimeMillis());
        }
        if(entity.getLastModifyTime() == null) {
            entity.setLastModifyTime(System.currentTimeMillis());
        }
    }
}
